// 云函数入口文件
const cloud = require('wx-server-sdk')
const env = 'bbq-6gz7knah1c296b0f'
cloud.init(env)
const db = cloud.database({ env })


// 云函数入口函数
exports.main = async (event) => {
    return await db.collection('articles').aggregate()
    .lookup({
      from:'users',
      localField:'userId',
      foreignField:'authorId',
      as:'articleWithuser'
    })
    .lookup({
      from:'comments',
      localField:'_id',
      foreignField:'articleId',
      as:'articleWithcoment'
    })
    .match({_id:event.articleId}).end()
}